<br>
<?php builddiv_start(1, $lang['vote']) ?>
<table width="100%" border="0">
	<tr>
		<td align="center">
<?php
if(isset($_SESSION["logged_voting"]))
{
?>
<form method="post" action="index.php?n=community&sub=vote">
	<input type="submit" name="logout" value="<?php echo $language["logout"] ?>" />
</form>
<?php
}
else
{
?>
<?php
}
?>
		</td>
	</tr>
</table>
<center>
<h1><?php echo $lang['vote_login1'] ?></h1>
<?php echo $language["created_by"] ?> <a rel="nofollow" href="mailto:&#115;&#117;&#112;&#101;&#114;&#103;&#97;&#100;&#103;&#101;&#116;&#64;&#97;&#98;&#118;&#46;&#98;&#103;">SUPERGADGET</a></center>
<br />
<h2><center><?php echo $lang['vote_login2'] ?></center></h2>
<br />
<script type="text/javascript">
function validate_required(field, alerttxt)
{
	if (field.value==null || field.value=="")
		{alert(alerttxt);return false;}
return true;
}
function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_required(username, "<?php echo $language["not_entered_username"] ?>")==false)
			{username.focus();return false;}
		if (validate_required(password, "<?php echo $language["not_entered_password"] ?>")==false)
			{password.focus();return false;}
	}
}
</script>
<?php
if(isset($_POST["submit"]))
{
	$_SESSION["realm"] = urldecode($_POST["realm"]);
	$user_name = stripslashes($_POST["username"]);
	$user_pass = sha1(strtoupper($user_name.":".stripslashes($_POST["password"])));
	switchConnection("realmd", $_SESSION["realm"]);
	$results = execute_query("SELECT `id`, `username` FROM `account` WHERE `username` = '".mysql_real_escape_string($user_name)."' AND `sha_pass_hash` = '".$user_pass."' LIMIT 1");
	if(mysql_num_rows($results))
	{
		$row = mysql_fetch_assoc($results);
		$_SESSION["user_id"] = $row["id"];
		$_SESSION["user_name"] = $row["username"];
		$_SESSION["logged_voting"] = 1;
		$_SESSION["panel"] = "reward";
		$_SESSION["vote"] = 1;
		$_SESSION["reward"] = 1;
		echo "<meta http-equiv=refresh content=\"0;url=index.php?n=community&sub=vote\">";
		exit();
	}
	else
		$wrong = 1;
}
if(isset($wrong))
{
?>
<center><font color="red"><?php echo $language["wrong"] ?></font></center>
<?php
}
else
?>
<center><?php echo $lang["enter_name_and_pass"];
?></center>
<br />
<form action="index.php?n=community&sub=login" onsubmit="return validate_form(this)" method="post">
<table border="0" cellspacing="1" cellpadding="3" align="center">
	<tr>
		<td width="50%"><?php echo $lang["username"] ?></td>
		<td width="50%"><input type="text" name="username" /></td>
	</tr>
	<tr>
		<td><?php echo $lang["pass"] ?></td>
		<td><input type="password" name="password" /></td>
	</tr>
	<tr>
		<td><?php echo $lang["realm_name"] ?></td>
		<td>
			<select name="realm">
<?php
foreach($realms as $key => $data)
	echo "<option value=\"",urlencode($key),"\">",$key,"</option>";
?>
			</select>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<center><input type="submit" name="submit" value="<?php echo $lang["login"] ?>" />
			<input type="reset" value="<?php echo $lang["reset"] ?>" /></center>
		</td>
	</tr>
</table>
</form>

<?php builddiv_end() ?>